package com.ruoyi.framework.config;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;


/**
 * 通过ssh连接数据库
 * Created by pengfenglong on 2018/10/8.
 */

@Configuration
public class SSHContextListener implements InitializingBean, DisposableBean {

    private SSHConnection conexionssh;

    @Value("${ssh.agent.open:false}")
    private Boolean open;


    @Override
    public void afterPropertiesSet() throws Exception {
        try {

            if(open)conexionssh = new SSHConnection();
        } catch (Throwable e) {
            e.printStackTrace(); // error connecting SSH server
        }
    }

    @Override
    public void destroy() throws Exception {
        conexionssh.closeSSH(); // disconnect
    }


}
